package com.logic.comment.util.data;

import java.io.*;

public class Tolls {
    public static void main(String[] args) {
        String inputFile = "C:\\Users\\Administrator\\Desktop\\git\\server\\y3\\slg-game\\src\\main\\java\\com\\game\\comment\\util\\data\\0.txt"; // 输入文件路径
        String outputFile1 = "C:\\Users\\Administrator\\Desktop\\git\\server\\y3\\slg-game\\src\\main\\java\\com\\game\\comment\\util\\data\\1.txt"; // 输出文件路径
        String outputFile2 = "C:\\Users\\Administrator\\Desktop\\git\\server\\y3\\slg-game\\src\\main\\java\\com\\game\\comment\\util\\data\\2.txt"; // 输出文件路径

        try {
            // 读取输入文件
            BufferedReader reader = new BufferedReader(new FileReader(inputFile));
            StringBuilder contentBuilder1 = new StringBuilder();
            StringBuilder contentBuilder2 = new StringBuilder();

            String line;
            while ((line = reader.readLine()) != null) {

                contentBuilder1.append("[");
                contentBuilder2.append("[");

                // // 获取常数
                // if (!line.contains("%")) {
                //     contentBuilder2.append(line);
                // }

                // // 获取百分数
                // if (line.contains("|")) {
                //     String[] split = line.split("\\|");
                //     for (String item : split) {
                //         Double v = Double.parseDouble(item);
                //         contentBuilder1.append(v).append(",");
                //
                //     }
                // } else {
                //     Double v = Double.parseDouble(line);
                //     for (int i = 0; i < 6; i++) {
                //
                //         contentBuilder1.append(v).append(",");
                //     }
                //
                // }

                // 获取百分数
                if (line.contains("|")) {
                    String[] split = line.split("\\|");
                    for (String item : split) {
                        int i = Integer.parseInt(item);
                        // Double v = Double.parseDouble(item);
                        contentBuilder1.append(i).append(",");
                    }
                } else {
                    int i = Integer.parseInt(line);
                    // Double v = Double.parseDouble(item);
                    contentBuilder1.append(i).append(",");
                }


                contentBuilder1.append("]").append("\n");
                contentBuilder2.append("]").append("\n");
            }

            reader.close();

            // 将修改后的内容写入输出文件
            BufferedWriter writer1 = new BufferedWriter(new FileWriter(outputFile1));
            String replace1 = contentBuilder1.toString().replace(",]", "]");
            writer1.write(replace1);
            writer1.close();

            BufferedWriter writer2 = new BufferedWriter(new FileWriter(outputFile2));
            String replace2 = contentBuilder2.toString().replace(",]", "]");
            writer2.write(replace2);
            writer2.close();
        } catch (IOException e) {
            System.err.println("发生错误：" + e.getMessage());
        }
    }
}
